﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    [ObjectEvent]
    public class Features_ComboComponentEvent : ObjectEvent<Features_ComboComponent>, IAwake
    {
        public void Awake()
        {
            Get().Awake();
        }
    }
    public class Features_ComboComponent : BattleEventComponent
    {
        public override BattleEventType[] EventType { get; set; } = new BattleEventType[] { BattleEventType.AttackSuccess };

        public override async Task RunEvent(BattleEventType eventType, FightModel fightModel, params object[] param)
        {
            DamageInfo damageInfo = param[0] as DamageInfo;
            BattleCard baseCard = GetEntity<BattleCard>();
            if (damageInfo.AttackCard == baseCard)
            {
                List<BattleCard> ShowCard = new List<BattleCard>();
                int Gorgeous = baseCard.GetComponent<SpellCardComponent>().Gorgeous;
                foreach (var a in baseCard.Owner[CardPlace.Cemetery].Cards)
                {
                    if (a.GetComponent<SpellCardComponent>().Gorgeous == Gorgeous)
                        ShowCard.Add(a);
                }
                SearchInfo searchInfo = new SearchInfo()
                {
                    Condition = (x) =>
                    {
                        return (x.Count == 1);
                    },
                    MaxChooseNum = 1,
                    OnSure = (x) =>
                    {
                        x[0].Move(x[0].Owner[CardPlace.SpellChain]);
                    },
                    ShowCard = ShowCard,
                };
            await BattleEventWatcherComponent.Single.RunEvent(BattleEventType.ShowWindow, fightModel, WindowType.Search, searchInfo);
            }
        }
    }
}
